#include "../../include/client_handle.h"

/***************************************************
函数名:cutStr
功能:将字符串str在字符c处分割，前后两段
分别赋给left和right，left最大长度为n，str最大
长度为max
传入参数:char str[],char left[], int n, char right[],int max, char c
返回值:无
***************************************************/
void cutStr(char str[],char left[], int n, char right[],int max, char c)
{
    int i,k,j;
    for(i = 0 ; i < n ;i++)
    {
        if(str[i] == c)                             //c为str的分割符
        break;
    }
    if(i == n)
    {
        i = -1;
    }
    else
    {
        memset(left,0,strlen(left));
        for(k = 0 ; k < i ; k++)
        {
            left[k] = str[k];         //c左边的字符串赋给left[] 
        }
    }
    for(j = i+1 ; j < max;j++)
    {
        if(str[j] == '\0')
        break;
        right[j-i-1] = str[j];     //c右边的字符串给right[]
    }
    left[i] = '\0';
    if(j < max)
    {
		right[j-i-1] = '\0';
    }	
    else
    {
		right[max] = '\0';
    }
}

/***************************************************
函数名:common_use_words
功能:常用语替换
传入参数:char msg[]
返回值:无
***************************************************/
void common_use_words(char msg[])
{
    int i=0,j=0;
	char common[MAXLEN];
    char tmp[MAXLEN];
	if(msg[0] == '/')
	{
		my_strcpy(tmp,msg);
		memset(msg,0,strlen(msg));
		for(i=1;i<MAXLEN;i++)
		{
			if(tmp[i] != '/')
			{
			    msg[i-1] = tmp[i];
			}
			else
			{
			    break;
			}
		}
		msg[i-1] = ',';
		msg[i] = '\0';
		i++;
		for(j=0;i<MAXLEN;i++,j++)
		{
		    if(tmp[i] != '\0')
		    {
		        common[j] = tmp[i];
		    }
		    else
		    {
			break;
		    }
		}
		common[j] = '\0';
		if(my_strcmp(common,"welcome") == 0)
		{
		    strcat(msg,"欢迎来到我们的聊天室^_^");         //连接字符串
			return ;
		}
		strcat(msg,common);
		
	}
}
/***************************************************
函数名:expression
功能:常用表情替换
传入参数:char name[],char msg[],int m
返回值:无
***************************************************/
void expression(char name[],char msg[])
{
	if(my_strcmp(msg,":)") == 0)
	{
	    sprintf(msg,"%s 做了个笑脸!",name);
	}
	if(my_strcmp(msg,":(") == 0)
	{
	    sprintf(msg,"%s 表情很沮丧!",name);
	}
	if(my_strcmp(msg,"囧") == 0)
	{
	    sprintf(msg,"%s 表情很囧!",name);
	}
	if(my_strcmp(msg,"哈哈") == 0)
	{
	    sprintf(msg,"哈哈 ^_^");
	}
	if(my_strcmp(msg,"汗") == 0)
	{
	    sprintf(msg,"~_~|||");
	}
	if(my_strcmp(msg,"晕") == 0)
	{
	    sprintf(msg,"＠_＠");
	}
}




